package com.dp.mallchat.common.chat.service.strategy;

import com.dp.mallchat.common.common.exception.ErrorEnum;
import com.dp.mallchat.common.common.utils.AssertUtil;
import com.dp.mallchat.common.user.service.handler.MsgHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: dupeng
 * @CreateTime: 2024-06-28  15:49
 * @Description: 消息处理器工厂
 */
public class MsgHandlerFactory {

    private static final Map<Integer, AbstractMsgHandler> msgHandlerMap = new HashMap<>();


    public static AbstractMsgHandler getStrategyNoNull(Integer type) {
        AbstractMsgHandler abstractMsgHandler = msgHandlerMap.get(type);
        AssertUtil.isNotEmpty(abstractMsgHandler, "消息处理器不存在");
        return abstractMsgHandler;
    }

    public static void register(Integer type, AbstractMsgHandler msgHandler){
        msgHandlerMap.put(type, msgHandler);
    }
}
